package com.mattgarner.jaddas.node;

import java.util.ArrayList;
import java.util.HashMap;



public class CurrentStateManager {
	private static CurrentStateManager instance;
	private ArrayList<RemoteNode> remoteNodes;
	private HashMap<Integer, RemoteClient> remoteClients;
	private RemoteClient[] dummyArray;
	
	// constructor
	public CurrentStateManager() {
		remoteNodes = new ArrayList<RemoteNode>();
		remoteClients = new HashMap<Integer, RemoteClient>();
		dummyArray = new RemoteClient[1];
		
		
	}
	
	// singleton method
	public final static CurrentStateManager getInstance() {
		if(instance == null) { 
			instance = new CurrentStateManager();
		}
		return instance;
	}
	
	// please use synchronized methods to help ensure thread-safety
	public final synchronized void addRemoteClient(int clientID, RemoteClient remoteClient) {
			remoteClients.put(clientID, remoteClient);
	}
	
	public final synchronized void removeRemoteClient(int clientID) {
		remoteClients.remove(clientID);
	}
	
	public final synchronized RemoteClient[] getRemoteClients() {
		return remoteClients.values().toArray(dummyArray);
	}
}
